package com.gemme.gemme.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.gemme.gemme.R;

import androidx.annotation.Nullable;

/**
 * @Author: yangcheng
 * @CreateDate: 2020/7/1 10:12
 */
@SuppressLint("AppCompatCustomView")
public class CommentCheckBox extends ImageView {


        private boolean isCheck = false;
        private OnChangeLIstener onChangeLIstener;

        public CommentCheckBox(Context context) {
                this(context,null);
        }

        public CommentCheckBox(Context context, @Nullable AttributeSet attrs) {
                this(context, attrs,0);
        }

        public CommentCheckBox(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
                super(context, attrs, defStyleAttr);
                initView();
        }

        private void initView() {
//                setBackgroundResource(R.drawable.checkbox_unselect);
                setEnabled(true);
                setChecked(isCheck);
                setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View view) {
                                isCheck = !isCheck;
                                setChecked(isCheck);
                                if (onChangeLIstener != null){
                                        onChangeLIstener.onChangeLIstener();
                                }
                        }
                });
        }

        public boolean isChecked() {
                return isCheck;
        }

        public void setChecked(boolean isCheck) {
                this.isCheck = isCheck;
                if(isCheck){
                        setBackgroundResource(R.drawable.pc_dengji_select);
                }else{
                        setBackgroundResource(R.drawable.pc_dengji_normal);
                }
        }

        public void setOnChangeLIstener(OnChangeLIstener onChangeLIstener){

                this.onChangeLIstener = onChangeLIstener;
        }
}

